import React from 'react'
import {useDispatch , useSelector} from 'react-redux'
import{increment , decrement} from "../../store/slice/countSlice"

export default function Count() {
  const dispatch = useDispatch()

  const count = useSelector((state) => state.count.count)

  //累加
  const incrementHandle = () => {
    dispatch(increment(20))
  }

  //累减
  const decrementHandle = () => {
    dispatch(decrement(5))
  }

  //基数累减
  const ifOddDecrementHandle = () => {
    if (count % 2 !== 0) {
      dispatch(decrement(5))
    }
  }

  // /等待2秒累加
  const waitincrementHandle = () => {
    dispatch(increment(20))
  }

  return (
    <div>
      <h1>我是Count组件我的count值是{count}</h1>
      <p>Movie组件的电影条数是{  }</p>
      <button onClick={incrementHandle}>累加</button>
      <button onClick={decrementHandle}>累减</button>
      <button onClick={ifOddDecrementHandle}>基数累减</button>
      <button onClick={waitincrementHandle}>等待2秒累加</button>
    </div>
  )
}
